package com.paobuji.aidebao.myapplication.ui;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.paobuji.aidebao.myapplication.R;
import com.paobuji.aidebao.myapplication.activity.BaseActivity;
import com.paobuji.aidebao.myapplication.appinterface.GetInterfaceObjctListener;
import com.paobuji.aidebao.myapplication.bean.AddQuestionUsefulResult;
import com.paobuji.aidebao.myapplication.bean.GetAllQuestion;
import com.paobuji.aidebao.myapplication.tool.MyIntentTools;
import com.paobuji.aidebao.myapplication.view.CustomTitlebar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class MyQuestionInfoActivity extends BaseActivity {

    @BindView(R.id.mainTitle)
    CustomTitlebar mainTitle;
    @BindView(R.id.questionTitle)
    TextView questionTitle;
    @BindView(R.id.questionWord)
    TextView questionWord;

    GetAllQuestion.DataBean.QuestionlistBean questionlistBean;
    @BindView(R.id.userfulImage)
    ImageView userfulImage;
    @BindView(R.id.userfulNum)
    TextView userfulNum;
    @BindView(R.id.activity_my_question_info)
    RelativeLayout activityMyQuestionInfo;

    MyIntentTools myIntentTools;
    int id = -1;
    Context context;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my_question_info);
        ButterKnife.bind(this);
        context = getApplicationContext();

        Bundle bundle = getIntent().getExtras();
        questionlistBean = (GetAllQuestion.DataBean.QuestionlistBean) bundle.getParcelable("question");

        myIntentTools = new MyIntentTools();

        //标题栏事件监测
        mainTitle.setAction(new CustomTitlebar.TitleBarOnClickListener() {
            @Override
            public void performAction(View view) {
                switch (view.getId()) {
                    case R.id.iv_left:
                        finish();
                        //Toast.makeText(MainActivity.this, "左边图片按钮", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.tv_left:
                        finish();
                        //Toast.makeText(MainActivity.this, "右边文字按钮", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.iv_right:
                        //Toast.makeText(MainActivity.this, "右边文字按钮", Toast.LENGTH_SHORT).show();
                        break;
                    case R.id.tv_right:
                        //Toast.makeText(MainActivity.this, "右边文字按钮", Toast.LENGTH_SHORT).show();
                        break;
                }
            }
        });

        setDataView();
    }

    /**
     * 修改界面数据
     */
    public void setDataView() {
        questionTitle.setText(questionlistBean.getQuesTitle());
        questionWord.setText(questionlistBean.getQuesAnswer());
//        userfulNum.setText(questionlistBean.getCountUseful() + "");
//        id = questionlistBean.getId();
    }

    /**
     * 点赞有用
     */
    public void setUserful(){
//        if(id != -1){
//            myIntentTools.addQuestionUseful(context,id);
//            myIntentTools.setGetInterfaceObjctListener(new GetInterfaceObjctListener() {
//                @Override
//                public void getObjectDate(Object data) {
//                    if(((AddQuestionUsefulResult)data).getCode() == 0){
//                        questionlistBean.setCountUseful(questionlistBean.getCountUseful() + 1);
//                        userfulNum.setText(questionlistBean.getCountUseful() + "");
//                    }
//                }
//            });
//        }
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {

    }

    @OnClick({R.id.userfulImage, R.id.userfulNum, R.id.activity_my_question_info})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.userfulImage:
                setUserful();
                break;
            case R.id.userfulNum:
                setUserful();
                break;
            case R.id.activity_my_question_info:
                setUserful();
                break;
        }
    }
}
